package com.zxl.manager.privacy.utils.track;

import android.app.Activity;
import android.content.Context;

import com.umeng.analytics.MobclickAgent;
import com.zxl.manager.privacy.utils.ActivityLifecycle;
import com.zxl.manager.privacy.utils.ApplicationHelper;
import com.zxl.manager.privacy.utils.utils.LogUtils;

/**
 * Created by Administrator on 2016/8/26.
 */
public class MobclickAgentHelper {

    public static void init(Context context, String channel) {
        try {
            MobclickAgent.startWithConfigure(new MobclickAgent.UMAnalyticsConfig(context, "57bf9b9ae0f55adf2d001ee8", channel, MobclickAgent.EScenarioType.E_UM_NORMAL, false));
            MobclickAgent.setDebugMode(ApplicationHelper.DEBUG);
            LogUtils.d("MobclickAgentHelper init " + channel);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void onResume(Context context) {
        try {
            MobclickAgent.onResume(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void onPause(Context context) {
        try {
            MobclickAgent.onPause(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void onKillProcess(Context context) {
        try {
            MobclickAgent.onKillProcess(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void reportError(Context context, String error) {
        try {
            MobclickAgent.reportError(context, error);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void onEvent(Context context, String type, String event) {
        try {
            Activity activity = ActivityLifecycle.getActivity();
            if (activity != null && !Activity.class.isInstance(context)) {
                context = activity;
            }
            MobclickAgent.onEvent(context, type, event);
            LogUtils.d("onEvent : " + type + ", " + event);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}
